package com.xia.netty.thread.lockSupport;

public class WaitAndNotifyDemo extends Thread {

    @Override
    public void run() {
        synchronized (this) {
            System.out.println("before notify");
            // 唤醒wait阻塞的线程
            notify();
            System.out.println("after notify");
        }
    }

        public static void main(String[] args) throws InterruptedException {

            WaitAndNotifyDemo waitAndNotifyDemo = new WaitAndNotifyDemo();
            /**
             * 在使用notify之前必须先使用wait,反之,主线程会一直阻塞
             */
            synchronized (waitAndNotifyDemo) {
                waitAndNotifyDemo.start();
                Thread.sleep(3000);
                System.out.println("before wait");
                //阻塞当前线程  main
                waitAndNotifyDemo.wait();
                System.out.println("after wait");
            }
        }
}
